package com.dzsw.netty.future;

public class InterruptionInJavaThread extends Thread {

    public static final boolean ON = true;

    public static final boolean OFF = false;

    private volatile boolean status = ON;

    public static void main(String[] args) throws InterruptedException {
        InterruptionInJavaThread t = new InterruptionInJavaThread();
        //start thread
        t.start();
        Thread.sleep(1000);
//        t.stopThread();
        Thread.sleep(1000);
        //interrupt thread
        t.interrupt();

        System.out.println("main end");

    }

    @Override
    public void run() {
        run1();
    }

    public void stopThread() {
        this.status = OFF;
    }

    private void run0() {
        while(true){
            if(Thread.currentThread().isInterrupted()){
                System.out.println("Yes,I am interruted,but I am still running");
                return;

            }else{
                System.out.println("not yet interrupted");
            }
        }
    }

    private void run1() {
        while(status){
            try {
                Thread.sleep(10000000);
            } catch (Exception e) {
                System.out.println("caught exception: "+e);
            }
        }
    }

}
